var querys = require('../db/mysql')

// 获取所有信息
exports.findAllInfo = function(sql,params,callback){
  querys(sql, params, function (error, results, fields) {
    if (error) throw error
    var list = {
      code: 0,
      msg: '',
      count: 0,
      data: results
    }
    callback(list)
  })
}

// 获取某个信息
exports.findOneInfo = function(sql,params,callback){
  querys(sql,params,function(error,results,fields){
    if (error) throw error
    var list = {
      code: 0,
      msg: '',
      count: results.length,
      data: results
    }
    callback(list)
  })
}

// 添加信息
exports.addInfo = function(sql,params,callback){
  querys(sql,params,function(error,results,fields){
    if (error) throw error
    callback(results)
  })
}

// 删除信息
exports.deleteInfo = function(sql,params,callback){
  querys(sql,params,function(error,results,fields){
    if (error) throw error
    callback(results)
  })
}

// 修改信息
exports.updateInfo = function(sql,params,callback){
  querys(sql,params,function(error,results,fields){
    if (error) throw error
    callback(results)
  })
}

// 获取数据条数
exports.getInfoCount = function(sql,params,callback){
  querys(sql,params,function(error,results,fields){
    if (error) throw error
    callback(results[0].total)
  })
}

// 用户登录
exports.userLogin = function(sql,params,callback){
  querys(sql,params,function(error,results,fields){
    if (error) throw error
    callback(results)
  })
}